import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'nprogress/nprogress.css'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import util from './utils/util'
import req from './utils/request'
import moment from 'moment';
import VueRouter from 'vue-router'
import '@/permission' 
import AMapLoader from "@amap/amap-jsapi-loader";
import {Base64} from 'js-base64'
import { options } from 'less'
import VueCookies from 'vue-cookies';
Vue.use(VueCookies);
// 引入高德地图
AMapLoader.load({
  'key': 'e73ab2f8ed721d52f9f6f7ca3de2c3c7',
  'version': '2.0',
  'plugins': ['AMap.Scale', 'AMap.GeoJSON']
}).then((AMap) => {
  Vue.use(AMap)
  // Vue.prototype.$AMap = AMap
})
Vue.prototype.$Base64 = Base64;
Vue.use(util)
Vue.use(Antd)
Vue.use(VueRouter)
Vue.config.productionTip = false
//将axios挂载到原型上
Vue.prototype.$http = req
// 设置全局访问
Vue.prototype.$moment = moment;
// 解决Ant Desgin UI导航栏中重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 用于控制a-input组件只能输入数字和小数点
// 自定义指令 v-numeric
Vue.directive('numeric', {
  bind(el, binding, vnode) {
    el.oninput = function(e) {
      if (e.inputType === 'deleteContentBackward' || e.inputType === 'deleteContentForward') {
        return;
      }
 
      const current = e.target.value;
      const beforeDecimal = current.split('.')[0];
      const afterDecimal = current.split('.')[1];
 
      let numericString = current.replace(/[^0-9.]/g, ''); // 移除所有非数字和点
      if (numericString.split('.').length > 2) {
        // 只允许一个小数点
        numericString = numericString.split('.').slice(0, 2).join('.');
      }
 
      if (beforeDecimal.startsWith(0)) {
        // 首位不能为0，除非只有一个0
        numericString = numericString.replace(/^0+(?!\.|$)/, '');
      }
 
      // 如果有小数点，保留一位小数
      if (afterDecimal && afterDecimal.length > 5) {
        numericString = beforeDecimal + '.' + afterDecimal.charAt(0);
      }
 
      e.target.value = numericString;
      vnode.elm.dispatchEvent(new Event('input')); // 触发input事件更新数据
    };
  },
  unbind(el) {
    el.oninput = null;
  }
});


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
